package com.ccqlk.lightpointrelation;

import cn.idev.excel.FastExcel;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.support.ExcelTypeEnum;
import cn.idev.excel.write.metadata.style.WriteCellStyle;
import cn.idev.excel.write.style.HorizontalCellStyleStrategy;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.List;

public class 箱变数据筛选正常异常 {
    public static void main(String[] args) {
        String readUrl = "C:\\Users\\13525\\Desktop\\沙区踩点信息表-2.xlsx";
        String writeUrl1 = "C:\\Users\\13525\\Desktop\\沙区踩点信息表-2-normal.xlsx";
        String writeUrl2= "C:\\Users\\13525\\Desktop\\沙区踩点信息表-2-no-pole.xlsx";

        List<DataInfo> objects = FastExcel.read(readUrl).head(DataInfo.class).doReadAllSync();


        List<DataInfo> normalList = objects
                .stream()
                .filter(data -> StringUtils.isNotBlank(data.get备注()) && data.get备注().contains("-"))
                .toList();

        objects.removeAll(normalList);


        List<DataInfo1> listNormal = normalList
                .stream()
                .map(data -> {
                    DataInfo1 dataInfo1 = new DataInfo1();
                    BeanUtils.copyProperties(data, dataInfo1);
                    String[] split = data.get经纬度().split("\n");
                    dataInfo1.setX坐标(split[0]);
                    dataInfo1.setY坐标(split[1]);
                    return dataInfo1;
                })
                .toList();
        List<DataInfo1> listNoPole = objects
                .stream()
                .map(data -> {
                    DataInfo1 dataInfo1 = new DataInfo1();
                    BeanUtils.copyProperties(data, dataInfo1);
                    String[] split = data.get经纬度().split("\n");
                    dataInfo1.setX坐标(split[0]);
                    dataInfo1.setY坐标(split[1]);
                    return dataInfo1;
                })
                .toList();

        // 设置单元格样式：自动换行
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        contentWriteCellStyle.setWrapped(true); // 👈 关键点：自动换行

        HorizontalCellStyleStrategy styleStrategy =
                new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle);


        FastExcel.write(writeUrl1).registerWriteHandler(styleStrategy).excelType(ExcelTypeEnum.XLSX).head(DataInfo1.class).sheet().doWrite(listNormal);
        FastExcel.write(writeUrl2).registerWriteHandler(styleStrategy).excelType(ExcelTypeEnum.XLSX).head(DataInfo1.class).sheet().doWrite(listNoPole);
    }

    @Data
    public static class DataInfo{
        @ExcelProperty
        private String id;
        @ExcelProperty
        private String 箱变名称;
        @ExcelProperty
        private String 经纬度;
        @ExcelProperty
        private String 控制器编号;
        @ExcelProperty
        private String 箱变出线回路;
        @ExcelProperty
        private String 二级配电柜名称;
        @ExcelProperty
        private String 回路数;
        @ExcelProperty
        private String 路段名称;
        @ExcelProperty
        private String 灯杆数量;
        @ExcelProperty
        private String 备注;
    }


    @Data
    public static class DataInfo1{
        @ExcelProperty
        private String id;
        @ExcelProperty
        private String 箱变名称;
        @ExcelProperty
        private String X坐标;
        @ExcelProperty
        private String Y坐标;
        @ExcelProperty
        private String 经纬度;
        @ExcelProperty
        private String 控制器编号;
        @ExcelProperty
        private String 箱变出线回路;
        @ExcelProperty
        private String 二级配电柜名称;
        @ExcelProperty
        private String 回路数;
        @ExcelProperty
        private String 路段名称;
        @ExcelProperty
        private String 灯杆数量;
        @ExcelProperty
        private String 备注;
    }
}
